export default function (app) {
  function dateFormat($filter) {
    'ngInject';

    const dateFilter = $filter('date');

    function linkFn(scope, elm, attrs, ctrl) {
      function formatter(value) {
        return dateFilter(value, 'yyyy-MM-dd');
      }

      function parser() {
        return ctrl.$modelValue;
      }

      ctrl.$formatters.push(formatter);
      ctrl.$parsers.unshift(parser);
    }
    return {
      restrict: 'A',
      link: linkFn,
      require: 'ngModel',
    };
  }

  app.directive('dateFormat', dateFormat);
}
